<?php
/**
 * Created by PhpStorm.
 * User: Sunwu
 * Date: 2017/9/18
 * Time: 12:34
 */

class Curl{
    /**
     * get请求
     * @param string $url
     * @return mixed
     */
    public static function doGet($url)
    {
        //初始化
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL,$url);
        // 执行后不直接打印出来
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        // 跳过证书检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // 不从证书中检查SSL加密算法是否存在
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        //执行并获取HTML文档内容
        $output = curl_exec($ch);

        //释放curl句柄
        curl_close($ch);

        return $output;
    }

    /**
     * psot请求
     * @param string $url
     * @param array $post_data
     * @param array | boolean $header
     * @return mixed
     */
    public static function doPost($url,$post_data,$header)
    {
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        // 执行后不直接打印出来
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // 设置请求方式为post
        curl_setopt($ch, CURLOPT_POST, true);
        // post的变量
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        // 请求头，可以传数组
        curl_setopt($ch, CURLOPT_HEADER, $header);
        // 跳过证书检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // 不从证书中检查SSL加密算法是否存在
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        $output = curl_exec($ch);
        curl_close($ch);

        return $output;
    }
}


//$curl=new Curl();
//$res=$curl->doGet($url);
//var_dump($res);
//$url="http://gu.qq.com/hk00700/gp";
//$curl=curl_init($url);
//curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//将执行结果返回
//curl_setopt($curl, CURLOPT_HEADER, false);//不处理头信息
//$res=curl_exec($curl);
//file_put_contents('res.txt',$res);
//curl_close($curl);
